﻿using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using ST.Torch.WebApi.Core.Entities.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;


namespace ST.Torch.WebApi.Application.Utils.Services
{
    public class UtilExcelService : IUtilExcelService, ITransient
    {
        private readonly IRepository<UtilExcel> _UtilExcelRepository;

        public UtilExcelService(IRepository<UtilExcel> UtilExcelRepository)
        {
            _UtilExcelRepository = UtilExcelRepository;
        }

        public IRepository<UtilExcel> GetRepository()
        {
            return _UtilExcelRepository;
        }
        #region curd
        public void Insert(UtilExcel entity)
        {
            _UtilExcelRepository.Insert(entity);
        }
        public async Task InsertAsync(UtilExcel entity, string[] Includes = null)
        {
            await _UtilExcelRepository.InsertAsync(entity);
        }
        public void Update(UtilExcel entity, string[] Includes = null)
        {
            if (Includes == null)
                _UtilExcelRepository.Update(entity);
            else
                _UtilExcelRepository.UpdateInclude(entity, Includes);

        }
        public async Task UpdateAsync(UtilExcel entity, string[] Includes = null)
        {
            if (Includes == null)
                await _UtilExcelRepository.UpdateAsync(entity);
            else
                await _UtilExcelRepository.UpdateIncludeAsync(entity, Includes);
        }
        public void Delete(UtilExcel entity, bool IsSoft = false)
        {
            
                _UtilExcelRepository.Delete(entity);
            

        }
        public async Task DeleteAsync(UtilExcel entity, bool IsSoft = false)
        {
            
                await _UtilExcelRepository.DeleteAsync(entity);
            

        }
        public bool Any(Expression<Func<UtilExcel, bool>> predicate)
        {
            return _UtilExcelRepository.Any(predicate);
        }
        public async Task<bool> AnyAsync(Expression<Func<UtilExcel, bool>> predicate)
        {
            return await _UtilExcelRepository.AnyAsync(predicate);
        }
        public UtilExcel Single(Expression<Func<UtilExcel, bool>> predicate, bool tracking = false)
        {
            return _UtilExcelRepository.SingleOrDefault(predicate, tracking);

        }
        public async Task<UtilExcel> SingleAsync(Expression<Func<UtilExcel, bool>> predicate, bool tracking = false)
        {
      
                return await _UtilExcelRepository.SingleOrDefaultAsync(predicate, tracking);

           

        }
        public List<UtilExcel> Query(Expression<Func<UtilExcel, bool>> predicate, bool tracking = false)
        {
            return _UtilExcelRepository.AsQueryable(tracking).Where(predicate).OrderByDescending(u => u.CreateTime).ToList();
        }
        public async Task<List<UtilExcel>> QueryAsync(Expression<Func<UtilExcel, bool>> predicate, bool tracking = false)
        {

               return await _UtilExcelRepository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToListAsync();
         
        }

        public PagedList<UtilExcel> QueryPage(Expression<Func<UtilExcel, bool>> predicate, PageReq page, bool tracking = false)
        {
            return _UtilExcelRepository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToPagedList(page.page, page.limit);
        }
        public async Task<PagedList<UtilExcel>> QueryPageAsync(Expression<Func<UtilExcel, bool>> predicate, PageReq page, bool tracking = false)
        {
            return await _UtilExcelRepository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToPagedListAsync(page.page, page.limit);
        }




        #endregion




    }
}
